package hhm.spring.springmvc;

import hhm.spring.pojo.Config;
import hhm.spring.pojo.HHMResponse;
import hhm.spring.springmvc.base.BaseController;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.session.SessionRegistry;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/ra/security")
@ResponseBody
public class SecurityController extends BaseController {

    @Autowired
    private SessionRegistry sessionRegistry;
    private Log logger = LogFactory.getLog(SecurityController.class);


    @Autowired
    private Config config;

    @RequestMapping(value = "/getCurrentUserSize")
    public HHMResponse getCurrentUserSize() {


        hhmResponse.setSuccess(true).setMsg("当前存在的用户数量是:" + sessionRegistry.getAllPrincipals().size());
        return hhmResponse;

    }


    @RequestMapping(value = "/getConfig")
    public HHMResponse getConfig() {
        hhmResponse.setSuccess(true).setMsg("读取的配置文件的值为:" + config.getAppName());
        return hhmResponse;

    }

    @RequestMapping(value = "/setConfig")
    public HHMResponse setConfig(String value) {
        config.setAppName(value);
        return hhmResponse.setSuccess(true).setMsg("修改成功");

    }

}
